#pragma once

#include <Defines.hpp>
#include <Window.hpp>
#include <SDL2/SDL_vulkan.h>
#include <vulkan/vulkan.hpp>
#include <vkDevice.hpp>
#include <VkSwapChain.hpp>

namespace NaturalEngine {
    class VkWindow : public IDeviceSurfaceProvider, public IDeviceExtensionsProvider, public Window {
    public:
        VkWindow(const i32 width, const i32 height) : Window(width, height, SDL_WINDOW_VULKAN) {

        }

        void CreateSurface(const vk::Instance &instance, vk::SurfaceKHR &surface) const override {
            surface = nullptr;
            VkSurfaceKHR result;
            if (!SDL_Vulkan_CreateSurface(_handler, instance, &result))
                throw std::runtime_error("Failed to create SDL surface");
            surface = result;
        }

        void GetExtensions(vector<cstr> &extensions) const override {
            u32 count;
            if (!SDL_Vulkan_GetInstanceExtensions(_handler, &count, nullptr))
                throw std::runtime_error("Failed to get SDL surface extensions");
            extensions.resize(count);
            if (!SDL_Vulkan_GetInstanceExtensions(_handler, &count, extensions.data()))
                throw std::runtime_error("Failed to get SDL surface extensions");
        }

    private:
        std::unique_ptr<VkSwapchain> _swapchain;
    };
}
